|
1
|
|
|
import * as fs from 'fs' |
|
2
|
|
|
import * as os from 'os' |
|
3
|
|
|
import OS from '../client/OS' |
|
4
|
|
|
import zPerformanceIni from '../templates/zPerformanceIni' |
|
5
|
|
|
import {ensureDirectoryExists} from '../utils/filesystem' |
|
6
|
|
|
import {jaleHomeDir, jaleLogsPath} from '../utils/jale' |
|
7
|
|
|
import Service from './service' |
|
8
|
|
|
|
|
9
|
|
|
abstract class PhpFpm extends Service { |
|
10
|
|
|
requireRoot = true |
|
11
|
|
|
isEndOfLife = false |
|
12
|
|
|
|
|
13
|
|
|
abstract versionName: string |
|
14
|
|
|
|
|
15
|
|
|
abstract configPath: string |
|
16
|
|
|
abstract iniDirectoryPath: string |
|
17
|
|
|
|
|
18
|
|
|
configRootPath = `${OS.getInstance().usrLocalDir}/etc/php` |
|
19
|
|
|
|
|
20
|
|
|
configure = async (): Promise<boolean> => { |
|
21
|
|
|
await this.updateConfiguration() |
|
22
|
|
|
await this.addPerformanceConfiguration() |
|
23
|
|
|
|
|
24
|
|
|
return true |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Update Php's www.conf configuration. |
|
30
|
|
|
*/ |
|
31
|
|
|
updateConfiguration = async (): Promise<void> => { |
|
32
|
|
|
let config: string = await fs.readFileSync(this.configPath, 'utf-8') |
|
33
|
|
|
|
|
34
|
|
|
config = config.replace(/^user = .+$/m, `user = ${os.userInfo().username}`) |
|
35
|
|
|
config = config.replace(/^group = .+$/m, 'group = staff') // TODO: Make this dynamic. GIDs dont work. |
|
36
|
|
|
config = config.replace(/^listen = .+$/m, `listen = ${jaleHomeDir}/jale.sock`) |
|
37
|
|
|
config = config.replace(/^;?listen\.owner = .+$/m, `listen.owner = ${os.userInfo().username}`) |
|
38
|
|
|
config = config.replace(/^;?listen\.group = .+$/m, 'listen.group = staff') // TODO: Make this dynamic. GIDs dont work. |
|
39
|
|
|
config = config.replace(/^;?listen\.mode = .+$/m, 'listen.mode = 0777') |
|
40
|
|
|
config = config.replace( |
|
41
|
|
|
/^;?php_admin_value\[error_log\] = .+$/m, |
|
42
|
|
|
`php_admin_value[error_log] = ${jaleLogsPath}/php.log` |
|
43
|
|
|
) |
|
44
|
|
|
|
|
45
|
|
|
return fs.writeFileSync(this.configPath, config) |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Create the z-performance.ini file which contains some optimized config settings. |
|
50
|
|
|
*/ |
|
51
|
|
|
addPerformanceConfiguration = async (): Promise<void> => { |
|
52
|
|
|
await ensureDirectoryExists(this.iniDirectoryPath) |
|
53
|
|
|
|
|
54
|
|
|
const path = `${this.iniDirectoryPath}/z-performance.ini` |
|
55
|
|
|
|
|
56
|
|
|
if (fs.existsSync(path)) { |
|
57
|
|
|
return |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return fs.writeFileSync(path, zPerformanceIni) |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
unLinkPhpVersion = async (): Promise<boolean> => { |
|
64
|
|
|
return OS.getInstance().serviceCtl.unlink(this.service) |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
linkPhpVersion = async (): Promise<boolean> => { |
|
68
|
|
|
return OS.getInstance().serviceCtl.link(this.service) |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
export default PhpFpm |
|
73
|
|
|
|